package whu.o2o;

import java.util.ArrayList;

import whu.o2o.R;

import whu.o2o.View.LoadDialog;
import whu.o2o.adapter.StudioAdapter;
import whu.o2o.connection.CommonHttpConnect;
import whu.o2o.connection.Params;
import whu.o2o.util.ConstantData;
import whu.o2o.util.ParseXml;
import whu.o2o.vo.StudioVO;
import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AbsListView;
import android.widget.AbsListView.OnScrollListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ListView;
import android.widget.TextView;

public class MystudioActivity extends BaseActivity implements OnClickListener,OnItemClickListener{
	private ListView mListView;
	private StudioAdapter mAdapter;
	private ArrayList<StudioVO> mStudioList;
	private String mTitle;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_common_list);
		getIntentData();
		initObject();
		initView();
		initListener();
		//initData();
	}


	@Override
	public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {

	}
	
	@Override
	protected void parseData(final String xml) {
		mStudioList.clear();

		mApplication.getThreadPool().execute(new Runnable() {

			@Override
			public void run() {
				ParseXml.getInstance().parseStudioXml(xml, mStudioList);
				mHttpListHandler.sendEmptyMessage(ConstantData.Data.PARSE_XML_MSG_CODE);
			}
		});

	}

	@Override
	protected void setAdapter() {
		if (mAdapter == null) {
			mAdapter = new StudioAdapter(this, mStudioList);
			mListView.setAdapter(mAdapter);
		} else {
			mAdapter.notifyDataSetChanged();
		}

	}

	private void getIntentData() {
		Intent intent = getIntent();
		if (intent != null) {
			mTitle = intent.getStringExtra("title");
		}
	}

	private void initObject() {
		mStudioList = new ArrayList<StudioVO>();
	}

	private void initView() {
		if (!TextUtils.isEmpty(mTitle)) {
			setTitle(mTitle);
		}
		mListView = (ListView) findViewById(R.id.listView);
	}

	private void initListener() {
		backBtnClick();
		mListView.setOnItemClickListener(this);
	}

	private void initData() {
		requestData();

	}

	private void requestData() {
		// Params params = new Params();
		// params.setUrl(mUrl);
		// params.setHandler(mHttpHandler);
		// params.setRequestType(ConstantData.Data.GET_HTTP);
		// params.setMsgCode(ConstantData.Data.GET_HTTP_RESULT_MSG_CODE);
		// params.setActivity(this);
		// params.setShowLoad(true);
		// LoadDialog.showDailog(this);
		// mApplication.getThreadPool().execute(new CommonHttpConnect(params));

		String[] names = { "武汉工作室", "武汉2工作室" };
		String[] introductions = { "相关简介", "相关简介" };
		String[] labels = { "武汉一日游", "武汉两日游" };
		int[] people = { 12, 133 };
		int[] focus = { 122, 13 };
		boolean[] focuseds = { true, false };
		for (int i = 0; i < names.length; i++) {
			StudioVO studioVO = new StudioVO();
			studioVO.setName(names[i]);
			studioVO.setPeopleCount(people[i]);
			studioVO.setFocusedCount(focus[i]);
			studioVO.setFocused(focuseds[i]);
			studioVO.setIntroduction(introductions[i]);
			studioVO.setLabel(labels[i]);
			mStudioList.add(studioVO);
		}

		setAdapter();
	}


	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		
	}

}
